﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CafeOnline.Common;

namespace CafeOnline.MvcFramework.Grid {
    public class ColumnType {
        public bool Nullable {
            get;
            private set;
        }

        public ColumnDataType DataType {
            get;
            private set;
        }

        public ColumnType(ColumnDataType dt, bool nullable) {
            Nullable = nullable;
            DataType = dt;
        }

        public ColumnType(Type dataType) {
            if ((dataType.IsGenericType) && (dataType.GetGenericTypeDefinition() == typeof(Nullable<>))) {
                Nullable = true;
                dataType = System.Nullable.GetUnderlyingType(dataType);
            }
            if (dataType.IsEnum) {
                DataType = ColumnDataType.Enum;
            } else if (dataType == typeof(DateTime)) {
                DataType = ColumnDataType.DateTime;
            } else if (dataType == typeof(Date)) {
                DataType = ColumnDataType.Date;
            } else if (dataType == typeof(FixedDateTime)) {
                DataType = ColumnDataType.FixedDateTime;
            } else if ((dataType == typeof(float)) || (dataType == typeof(double)) || (dataType == typeof(decimal))) {
                DataType = ColumnDataType.Decimal;
            } else if ((dataType == typeof(int)) || (dataType == typeof(long)) || (dataType == typeof(short)) ||
                       (dataType == typeof(uint)) || (dataType == typeof(ulong)) || (dataType == typeof(ushort)) || (dataType == typeof(byte))) {
                DataType = ColumnDataType.Number;
            } else if (dataType == typeof(bool)) {
                DataType = ColumnDataType.Boolean;
            } else {
                DataType = ColumnDataType.Generic;
            }
        }
    }
    public enum ColumnDataType {
        Generic,
        Number,
        Decimal,
        DateTime,
        Date,
        FixedDateTime,
        Enum,
        Boolean
    }
}
